package com.haier.uos.springcloud.basic.job;

import com.haier.uos.springcloud.basic.service.ICityDataService;
import com.haier.uos.springcloud.basic.service.IWeatherDataService;
import com.haier.uos.springcloud.basic.vo.City;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

public class WeatherDataSyncJob extends QuartzJobBean {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ICityDataService cityDataService;
    @Autowired
    private IWeatherDataService weatherDataService;
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("weather data sync job start");
        List<City> cityList = cityDataService.getCityList();
        for (City city : cityList) {
            weatherDataService.syncWeatherDataByCityId(city.getCityId());
        }
        logger.info("weather data sync job end");
    }
}
